<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@ page import="ws.SPWebService"%>
    <%@ page import="ws.WebServiceBean"%>
    <%@ page import="project.utils.Utils"%>
    <%@ page import="project.utils.Parser"%>
    <%@ page import="java.util.ArrayList"%>
    <%@ page import="java.util.HashMap"%>
    <%
        SPWebService sp = new SPWebService();
        WebServiceBean ws = sp.getWebServiceBeanPort();
    %>
    <%
        // Проверка, прошел ли пользователь авторизацию.
        if (session.getAttribute("userid") == null) {
    %><jsp:forward page="input.jsp"></jsp:forward>
    <%} else {// все хорошо, можно работать!

        String[][] responseArray = Utils.toArrays(ws.getUserByID(Integer.parseInt((String) session.getAttribute("userId"))));
        ArrayList<HashMap<String, ArrayList<String>>> user = Parser.parse(responseArray);
    %>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Редактирование личных данных</title>
        <style type="text/css">
            body {background-image: url(images/Sport.jpg);background-repeat: repeat-y;}
            body,td,th {color: #F60;text-align: center;}
            a:link {color: #0F0;text-decoration: none;}
            a:visited {color: #0F0;text-decoration: none;}
            a:hover {text-decoration: none;color: #060;}
            a:active {text-decoration: none;color: #F60;}
            .green {color: #0F0;}
        </style>
    </head>

    <body>
        <div align="center">
            <table width="864" border="1">
                <tr>
                    <th width="758" height="185" bgcolor="#000000" scope="col"><h1>
                            <strong class="В"><em>PLANET OF SPORT </em></strong><img
                                src="images/Planet.jpg" width="260" height="208" alt="" />
                        </h1></th>
                </tr>
                <tr>
                    <td height="57" bgcolor="#000000"><div align="center">
                            <h2 class="green">
                                <big>РЕДАКТИРОВАНИЕ ЛИЧНЫХ ДАННЫХ</big>
                            </h2>
                        </div></td>
                </tr>
                <tr>
                    <td height="294" bgcolor="#000000">
                        <%
                                if (request.getParameter("edit") != null) {
                                    String[] dataAboutUser = new String[9];
                                    dataAboutUser[0] = (String) session.getAttribute("userid");
                                    dataAboutUser[1] = request.getParameter("firstname");
                                    dataAboutUser[2] = request.getParameter("lastname");
                                    dataAboutUser[3] = request.getParameter("age");
                                    dataAboutUser[4] = request.getParameter("city");
                                    dataAboutUser[5] = request.getParameter("interests");
                                    dataAboutUser[6] = request.getParameter("contact_information");
                                    dataAboutUser[7] = request.getParameter("e-mail");
                                    dataAboutUser[8] = request.getParameter("login");

                                    String[][] responseArray_1 = Utils.toArrays(ws.changeProfileInfo(Utils.toList(dataAboutUser)));
                                    ArrayList<HashMap<String, ArrayList<String>>> answer = Parser.parse(responseArray_1);
                                    // Печатаем ответ сервера
                                    if (Boolean.parseBoolean(answer.get(0).get("errorhappend").get(0))) {
                                        out.println("<big><p align=\"center\" style=\"color:red;\">"
                                                + answer.get(0).get("message").get(0)
                                                + "</p></big>");
                                    } else {
                                        out.println("<big><p align=\"center\" style=\"color:#0F0;\">"
                                                + answer.get(0).get("message").get(0)
                                                + "</p></big>");
                                    }
                                }
                            }
                        %>
                        <form name="dataAboutUser" method="post" action="editUser.jsp">
                            <table width="500" align="center">
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>* Имя:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="firstname"
                                                   value="<%=user.get(0).get("firstname").get(0)%>" />
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>* Фамилия:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="lastname"
                                                   value="<%=user.get(0).get("lastname").get(0)%>" />
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>* Дата рождения:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td>
                                        <div align="left">
                                            <input type="text" name="age"
                                                   value="<%=user.get(0).get("age").get(0)%>" />
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>Родной город:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="city"
                                                   value="<%=user.get(0).get("city").get(0)%>" />
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>Интересы:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <textarea rows="5" cols="25" name="interests"><%=user.get(0).get("info").get(0).replace(" ", "&nbsp;")%></textarea>
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>Телефон:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="contact_information"
                                                   value="<%=user.get(0).get("contact_information").get(0)%>" />
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>* Адрес e-mail:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="e-mail"
                                                   value="<%=user.get(0).get("e-mail").get(0)%>" />
                                        </div></td>
                                </tr>
                                <tr>
                                    <td width="200px">
                                        <div align="right">
                                            <h3>* Логин:</h3>
                                        </div>
                                    </td>
                                    <td width="50px"></td>
                                    <td><div align="left">
                                            <input type="text" name="login"
                                                   value="<%=user.get(0).get("login").get(0)%>" />
                                        </div></td>
                                </tr>
                            </table>
                            <div align="center">
                                <input type="submit" name="edit" value="Сохранить" />
                            </div>
                        </form>
                        <p>&nbsp;</p>
                        <p>
                            <a href="Home.jsp">Вернуться на главную страницу</a>
                        </p>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
